﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class BaoCaoTon_DAO
    {
        private static BaoCaoTon_DAO m_instance = null;

        public static BaoCaoTon_DAO Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new BaoCaoTon_DAO();
                return m_instance;
            }
        }

        /// <summary>
        ///   them bao cao ton
        /// </summary>
        /// 

        public bool ThemBaoCaoTon(DateTime _ngayLap)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("ADD_BAOCAOTON", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@ngaybaocao", SqlDbType.SmallDateTime);
                cmd.Parameters["@ngaybaocao"].Value = _ngayLap.ToShortDateString();

                cmd.ExecuteNonQuery();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }


        /// <summary>
        ///   lay ma phieu bao cao ton max
        ///   
        /// </summary>
        /// 
        public DataTable LayMaBaoCaoTon()
        {
            DataTable result = new DataTable();
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("GET_BAOCAOTON_MAX", cnn);
                cmd.CommandType = CommandType.StoredProcedure;


                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(result);
                return result;
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }
    }
}
